$(function () {

    var itemIndex = 0;
	var indexct = 1;
	var page = 1;
    var tabLoadEndArray = [false, false, false];
    var tabLenghtArray = [28, 15, 47];
    var tabScroolTopArray = [0, 0, 0];
    
    // dropload
    var dropload = $('.khfxWarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">已无数据</div>'
        },
        loadDownFn: function (me) {
            setTimeout(function () {
                if (tabLoadEndArray[itemIndex]) {
                    me.resetload();
                    me.lock();
                    me.noData();
                    me.resetload();
                    return;
                }
                var result = '';
            	if(rewardType == 1)
            	{
                    $.getJSON(path + '/wx/r/judgesion/rewardListJsonPage.html?page=' + page + '&rewardType=1', function (data) {
                        //遍历json中的每个entry
                    	var isHasData = 0;
                    	result = '';

                    	//业绩奖励
                        $.each(data, function (entryindex, entry) {                   	
                            result
                            = ''
                            + '    <a href="' + path + '/wx/r/judgesion/reward_detail.html?id='+ entry['id'] +'">'
                            + '      <div class="item item-'+indexct+'">'
                            + '      	 <em class="em-'+entry['blState']+'">'+entry['blName']+'</em>'
                            + '        <span><i>'+entry['rewardAmt']+'元</i><p>奖励</p></span>'
                            + '        <div>'
                            + '          <ul>'
                            + '            <li>客户姓名：<b>'+entry['order'].name+'</b></li>'
                            + '            <li><p class="p-1">投资额：<b>'+entry['investmentAmt']/10000+'w</b></p><p class="p-2">奖励比例：<b>'+entry['percent']+'%</b></p></li>'
                            + '             <li>投资时间：<b>'+entry['createDate']+'</b></li>'
                            + '          </ul>'
                            + '        </div>'
                            + '     </div>'
                            + '  </a>';
                            indexct++;
                            isHasData = 1;
                            $('.content').append(result);  	
                        });
                        page++;
                        if(isHasData == 0)
                        {
                            tabLoadEndArray[itemIndex] = true;
                            
                        }	
                        me.resetload();
                    });             		
            	}
            	else if(rewardType == 0)//邀请奖励
            	{
                    $.getJSON(path + '/wx/r/judgesion/rewardListJsonPage.html?page=' + page + '&rewardType=0&rewardLeve=' + rewardLeve, function (data) {
                        //遍历json中的每个entry
                    	var isHasData = 0;
                    	result = '';

                    	//业绩奖励
                        $.each(data, function (entryindex, entry) {                   	
                            result
                            = ''
                            + '    <a href="' + path + '/wx/r/judgesion/reward_detail.html?id='+ entry['id'] +'">'
                            + '      <div class="item item-'+indexct+'">'
                            + '      	 <em class="em-'+entry['blState']+'">'+entry['blName']+'</em>'
                            + '        <span><i>'+entry['rewardAmt']+'元</i><p>奖励</p></span>'
                            + '        <div>'
                            + '          <ul>'
                            + '            <li>理财师：<b>'+encodeMobile(entry['order'].mobile) +'</b></li>'
                            + '             <li>投资时间：<b>'+entry['createDate']+'</b></li>'
                            + '          </ul>'
                            + '        </div>'
                            + '     </div>'
                            + '  </a>';
                            indexct++;
                            isHasData = 1;
                            $('.content').append(result);  	
                        });
                        page++;
                        if(isHasData == 0)
                        {
                            tabLoadEndArray[itemIndex] = true;
                            
                        }	
                        me.resetload();
                    });              		
            	}
              //邀请奖励
            }, 500);
        }
    });

    function encodeMobile(mobile)
    {
    	
    	return mobile.substring(0,3)+"****"+mobile.substring(8,11);;  
    }
    $('.tabHead span').on('click', function () {

        tabScroolTopArray[itemIndex] = $(window).scrollTop();
        var $this = $(this);
        itemIndex = $this.index();
        $(window).scrollTop(tabScroolTopArray[itemIndex]);
        
        $(this).addClass('active').siblings('.tabHead span').removeClass('active');
        $('.tabHead .border').css('left', $(this).offset().left + 'px');
        $('.khfxPane').eq(itemIndex).show().siblings('.khfxPane').hide();

        if (!tabLoadEndArray[itemIndex]) {
            dropload.unlock();
            dropload.noData(false);
        } else {
            dropload.lock('down');
            dropload.noData();
        }
        dropload.resetload();
    });
});